package com.niit.onlinemusicserver.controller;

import com.niit.onlinemusicserver.common.R;
import com.niit.onlinemusicserver.model.request.CartListRequest;
import com.niit.onlinemusicserver.service.CartListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 购物车功能接口
 * @Author: Jason
 * @date: 2023.6.29
 */
@RestController
public class CartController {

  @Autowired
  private CartListService cartListService;

  /**
   * 加入购物车
   * @param cartListRequest
   * @return
   */
  @PostMapping("/cart/add")
  public R addServerCart(@RequestBody CartListRequest cartListRequest) {
    return cartListService.addCartList(cartListRequest);
  }

  /**
   * 返回所有购物车项
   * @param userId
   * @return
   */
  @GetMapping("/cart/list")
  public R getCartList(@RequestParam("userId") Integer userId) {
    return cartListService.allCartList(userId);
  }

  /**
   * 删除购物车项
   * @param songIds
   * @return
   */
  @GetMapping("/cart/remove")
  public R removeCartList(@RequestParam("userId") Integer userId, @RequestParam("cartListIds") List<Integer> songIds) {
    return cartListService.deleteCartList(userId, songIds);
  }

}
